// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

// 云函数入口函数
exports.main = async (event, context) => {
  return cloud.callFunction({
    name: "model_user",
    data: {
      op: "update",
      id: event.user_id,
      openid: event.openid,
      photo: event.photo,
      username: event.username,
      type: event.type,
      phone: event.phone
    }
  }).then(res => {
    if (res.result.stats.updated == 1) {
      return cloud.callFunction({
        name: "model_user",
        data: {
          op: "select",
          key: "_id",
          value: event.user_id
        }
      }).then(res => {
        console.log(res.result);
        return res.result
      })
    } else {
      return "0"
    }
  })
}